package br.unifor.cct.mia.gui;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;
import java.util.Properties;

public class PropertieUtils {

	private Properties props = null;
	private String fileName = null;
	
	public PropertieUtils(String fileName) throws IOException {
		this.fileName = fileName;
		this.loadFile(fileName);
	}
	
	public void loadFile(String fileName) throws IOException {
		InputStream fis = this.getClass().getResourceAsStream(fileName);
		props = new Properties();		
		props.load(fis);
		fis.close();
	}
	
	public void save() throws URISyntaxException, IOException {
		File file = new File(this.getClass().getResource(fileName).toURI());
		FileOutputStream fos = new FileOutputStream(file);
		props.store(fos,"");
	}
	
	public String getProperty(String propertyName) {
		return props.getProperty(propertyName);
	}
	
	public void setProperty(String propertyName, String value) {
		props.setProperty(propertyName,value);		
	}
}
